package com.kejiguan.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kejiguan.ui.R;
import com.kejiguan.ui.model.SheduleObject;
import com.kejiguan.ui.model.SubSelectSheduleObject;

import java.util.List;

/**
 * Created by YYY on 16/8/18.
 */
public class SheduleObjectAdapterNew extends BaseAdapter{



    private List<SheduleObject> sheduleObjects;
    private Context context;
    private LayoutInflater layoutInflater;
    private View.OnClickListener onClickListener;

    public SheduleObjectAdapterNew(Context context,
                                            List<SheduleObject> sheduleObjects, View.OnClickListener onClickListener) {

        this.sheduleObjects = sheduleObjects;
        this.context=context;
        this.onClickListener=onClickListener;
        layoutInflater = LayoutInflater.from(context);

    }



    @Override
    public int getCount() {
        if (null==sheduleObjects)
        {
            return 0;
        }
        return sheduleObjects.size();
    }

    @Override
    public Object getItem(int position) {
        return sheduleObjects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SheduleObject sheduleObject=sheduleObjects.get(position);
        View view = null;

        if (layoutInflater != null) {

            view = layoutInflater
                    .inflate(R.layout.activity_add_shedule_object_item_layout, null);
            TextView textView = (TextView) view.findViewById(R.id.object_name);
            textView.setTag(R.id.recyclerview_item_position,position);
            textView.setOnClickListener(onClickListener);
            //获取自定义的类实例
            textView.setText(sheduleObject.getName());
        }
        return view;
    }

    public void setSheduleObjects(List<SheduleObject> sheduleObjects) {
        this.sheduleObjects = sheduleObjects;
        notifyDataSetChanged();
    }
}
